package service;

import java.util.List;

import javax.annotation.Resource;

import model.FollowPlan;
import model.Incident;
import model.Person;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import DAO.Userdao;

@Service("userService")
@Transactional
public class UserserviceImp implements Userservice {

	@Resource(name = "userDaoe")
	private Userdao userdao;

	/*
	 * @Override public User read(String fname,String lname) { User user = null;
	 * if(fname.equals("james") && lname.equals("jiang")){ user = new User();
	 * user.setId(1); user.setF_name(fname); user.setL_name(fname);
	 * user.setSalary(10000); } return user; }
	 * 
	 * 
	 * @Override public User read(int id) { // TODO Auto-generated method stub
	 * return userdao.search(id); }
	 * 
	 * 
	 * @Override public List<User> read() { return userdao.search(); }
	 */


	@Override
	public void insert(String fname,String lname,String position, int phone, String email, int age, String sex) {
		userdao.insert( fname, lname, position,  phone,  email,  age,  sex);
;	}


	@Override
	@Transactional(readOnly = false, rollbackFor = DataAccessException.class)
	public void insertIncident(String incident_location, String gen,
			String inital) {
		userdao.insertIncident(incident_location, gen, inital);
		// TODO Auto-generated method stub
		
	}


	@Override
	@Transactional(readOnly = false, rollbackFor = DataAccessException.class)
	public void insertPlan(String type, String des) {
		// TODO Auto-generated method stub
		userdao.insertPlan(type, des);
		
	}


	@Override
 	public List<Person> readPerson() {
		// TODO Auto-generated method stub
		return userdao.searchPerson();
	}


	@Override
 	public List<Incident> readIncident() {
		// TODO Auto-generated method stub
		return userdao.searchIncident();
	}


	@Override
 	public List<FollowPlan> readPlan() {
		// TODO Auto-generated method stub
		return userdao.searchPlan();
	}


	@Override
	public Person findPerson(int id) {
		
		// TODO Auto-generated method stub
		return userdao.findPerson(id);
	}


	@Override
	public Incident findIncident(int id) {
		// TODO Auto-generated method stub
		return userdao.findIncident(id);
	}


	@Override
	public FollowPlan findPlan(int id) {
		// TODO Auto-generated method stub
		return userdao.findPlan(id);
	}


	@Override
	@Transactional(readOnly = false, rollbackFor = DataAccessException.class)
	public void updatePerson(String type, int id, String info) {
		userdao.updatePerson(type, id, info);
		
	}


	@Override
	@Transactional(readOnly = false, rollbackFor = DataAccessException.class)
	public void deletePerson(int id) {
		userdao.deletePerson(id);// TODO Auto-generated method stub
		
	}


	@Override
	@Transactional(readOnly = false, rollbackFor = DataAccessException.class)
	public void updateIncident(String type, int id, String info) {
		userdao.updateIncident(type, id, info);
		// TODO Auto-generated method stub
		
	}


	@Override
	@Transactional(readOnly = false, rollbackFor = DataAccessException.class)
	public void deleteIncident(int id) {
		userdao.deleteIncident(id);
		// TODO Auto-generated method stub
		
	}


	@Override
	@Transactional(readOnly = false, rollbackFor = DataAccessException.class)
	public void updatePlan(String type, int id, String info) {
		userdao.updatePlan(type, id, info);
		// TODO Auto-generated method stub
		
	}


	@Override
	@Transactional(readOnly = false, rollbackFor = DataAccessException.class)
	public void deletePlan(int id) {
		userdao.deletePlan(id);
		// TODO Auto-generated method stub
		
	}

}
